#include "cpu/exec/template-start.h"

#define instr add

// static void do_execute() {
// 	DATA_TYPE result = op_dest->val + op_src->val;
// 	OPERAND_W(op_dest, result);

// 	cpu.eflags.CF = (result < op_dest->val);

//     cpu.eflags.SF = result >> (DATA_BYTE*8 -1);

//     int a = op_dest->val >> (DATA_BYTE*8 - 1);
//     int b = op_src->val >> (DATA_BYTE*8 - 1);

//     cpu.eflags.OF = (a == b) && (b != cpu.eflags.SF);
//     cpu.eflags.ZF = !result;
//     result ^= result >>4;
// 	result ^= result >>2;
// 	result ^= result >>1;
// 	cpu.eflags.PF = !(result & 1);
//     if(( (op_dest->val & 0xf) + (op_src->val & 0xf) ) >> 4) cpu.eflags.AF = 1;
//     else cpu.eflags.AF = 0;
// 	print_asm_template2();
// }

static void do_execute(){
    DATA_TYPE res = op_src->val + op_dest->val;
    OPERAND_W(op_dest, res);
    cpu.eflags.ZF = !res;
    cpu.eflags.SF = MSB(res);
    cpu.eflags.PF = get_pf(res);
    update_eflags_pf_zf_sf(res);
    if(MSB(op_dest->val) == MSB(op_src->val) && MSB(res) != MSB(op_dest->val))
        cpu.eflags.OF = 1;
    else cpu.eflags.OF = 0;
    if(res < op_dest->val && op_src->val > 0) cpu.eflags.CF = 1;
    else cpu.eflags.CF = 0;

    print_asm_template2();
}

make_instr_helper(i2a)
make_instr_helper(i2rm)
make_instr_helper(r2rm)
make_instr_helper(rm2r)

#if DATA_BYTE == 2 || DATA_BYTE == 4
make_instr_helper(si2rm)
#endif

#include "cpu/exec/template-end.h"